package future;

import org.junit.Test;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @author kxd
 * @datetime 2022/3/22 9:48
 */
public class CompletableFutureExamp2 {
    @Test
    public void test() throws ExecutionException, InterruptedException {

        CompletableFuture f1 = CompletableFuture.runAsync(() -> {
            System.out.println("T1");
            System.out.println("T1");
        });

        CompletableFuture f2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("T2 ");

            return "t2";
        });
        //t3
        CompletableFuture f3 = f1.thenCombine(f2, (__, ft) -> {
            System.out.println("T3");

            return "" + ft;
        });

        System.out.println(f3.join());
    }
}
